package capricornus.components.button
{
	import capricornus.components.sprite.AbstractComponent;
	import capricornus.components.utils.style.StyleType;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class Button extends TriggerButton
	{
		public function Button()
		{
			super();
			init();
		}
		
		private function init():void
		{
			this.buttonMode = true;
			
			_container.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown, false, 0, true );
			_container.addEventListener( MouseEvent.MOUSE_OUT, onMouseOut, false, 0, true );
			_container.addEventListener( MouseEvent.MOUSE_OVER, onMouseOver, false, 0, true );
			_container.addEventListener( MouseEvent.MOUSE_UP, onMouseUp, false, 0, true );
		}
		
		override public function destroy():void
		{
			super.destroy();
			
			_container.removeEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
			_container.removeEventListener( MouseEvent.MOUSE_OUT, onMouseOut );
			_container.removeEventListener( MouseEvent.MOUSE_OVER, onMouseOver );
			_container.removeEventListener( MouseEvent.MOUSE_UP, onMouseUp );
		}
		
		protected function onMouseDown( e:MouseEvent ):void
		{
			super.selected = true;
			if( _label )
			{
				_label.x++;
				_label.y++;
			}
		}
		
		protected function onMouseOut( e:MouseEvent ):void
		{
			currentSkin = _upSkinContainer;
			super.selected = false;
			super.overSelected = false;
			resetLabel();
		}
		
		protected function onMouseOver( e:MouseEvent ):void
		{
			currentSkin = _overSkinContainer;
			super.overSelected = true
		}
		
		protected function onMouseUp( e:MouseEvent ):void
		{
			super.selected = false;
			resetLabel();
		}
	}
}